package controler;

import java.util.ArrayList;
import java.util.Iterator;

import view.BaseHybridView;
import view.RoomView;
import view.trajectory.TargetView;

import model.trajectory.TargetModel;

public class SelectionManager
{
	public ArrayList<BaseHybridView> selectedRooms;
	public ArrayList<TargetModel> selectedTargets;
	
	public SelectionManager()
	{
		this.selectedRooms = new ArrayList<BaseHybridView>();
		this.selectedTargets = new ArrayList<TargetModel>();
	}
	
	public void addRoom(BaseHybridView room)
	{
		this.selectedRooms.add(room);
	}
	
	public void addTarget(TargetModel target)
	{
		target.setHighlighted(true);
		this.selectedTargets.add(target);
	}
	
	public void addAllRoom(ArrayList<RoomView> rooms)
	{
		for(Iterator<RoomView> it = rooms.iterator(); it.hasNext();)
		{
			BaseHybridView view = it.next();
			if(!selectedRooms.contains(view))
			{
				view.getModel().isSelected = true;
				selectedRooms.add(view);
			}
		}
	}
	
	public void addAllTargets(ArrayList<TargetModel> arrayList)
	{
		if(arrayList != null)
		{
			for(Iterator<TargetModel> it = arrayList.iterator(); it.hasNext();)
			{
				TargetModel model = it.next();
				if(!selectedTargets.contains(model))
				{
					model.setHighlighted(true);
					selectedTargets.add(model);
				}
			}
		}
	}
	
	public void clearRoomSelection()
	{
		for(Iterator<BaseHybridView> it = this.selectedRooms.iterator(); it.hasNext();)
		{
			it.next().getModel().isSelected = false;
		}
		this.selectedRooms.clear();
	}
	public void clearTargetSelection()
	{
		for(Iterator<TargetModel> it = this.selectedTargets.iterator(); it.hasNext();)
		{
			it.next().setHighlighted(false);
		}
		this.selectedTargets.clear();
	}
	
	public boolean isSelected(BaseHybridView view)
	{
		return this.selectedRooms.contains(view);
	}
	
	public boolean isSelected(TargetView view)
	{
		return this.selectedTargets.contains(view);
	}

	public ArrayList<BaseHybridView> getSelectedNodes() {
		// TODO Auto-generated method stub
		return this.selectedRooms;
	}
	
	public ArrayList<TargetModel> getSelectedTargets()
	{
		return this.selectedTargets;
	}

	public boolean nodeListIsEmpty() {
		// TODO Auto-generated method stub
		return this.selectedRooms.isEmpty();
	}

	public boolean targetListIsEmpty() {
		// TODO Auto-generated method stub
		return this.selectedTargets.isEmpty();
	}
}
